﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using ZG_member.Model;
namespace ZG_member.BLL
{
	/// <summary>
	/// wasteBook
	/// </summary>
	public partial class wasteBook
	{
		private readonly ZG_member.DAL.wasteBook dal=new ZG_member.DAL.wasteBook();
		public wasteBook()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

        public DataSet GetSQL(string sql)
        {
            return dal.GetSQL(sql);
        }


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(ZG_member.Model.wasteBook model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZG_member.Model.wasteBook model)
		{
			return dal.Update(model);
		}
        public bool Updatepoint(string memberid)
        {
            return dal.Updatepoint(memberid);
        }

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}
        public bool DeleteListbyCardid(string idlist) {
            return dal.DeleteListbyCardid(idlist);
        }
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZG_member.Model.wasteBook GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

        public string keyongjifen(string memberId, int day) {
            return dal.keyongjifen(memberId, day);
        }
            
		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public ZG_member.Model.wasteBook GetModelByCache(int id)
		{
			
			string CacheKey = "wasteBookModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (ZG_member.Model.wasteBook)objModel;
		}

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageNum"></param>
        /// <returns></returns>
        public DataSet Pagination(int pageSize, int pageNum,string strWhere)
        {
            return dal.Pagination(pageSize, pageNum,strWhere);
        }



		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ZG_member.Model.wasteBook> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<ZG_member.Model.wasteBook> DataTableToList(DataTable dt)
		{
			List<ZG_member.Model.wasteBook> modelList = new List<ZG_member.Model.wasteBook>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				ZG_member.Model.wasteBook model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new ZG_member.Model.wasteBook();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["terminalId"]!=null && dt.Rows[n]["terminalId"].ToString()!="")
					{
						model.terminalId=dt.Rows[n]["terminalId"].ToString();
					}
					if(dt.Rows[n]["operatorId"]!=null && dt.Rows[n]["operatorId"].ToString()!="")
					{
					model.operatorId=dt.Rows[n]["operatorId"].ToString();
					}
					if(dt.Rows[n]["memberCardId"]!=null && dt.Rows[n]["memberCardId"].ToString()!="")
					{
					model.memberCardId=dt.Rows[n]["memberCardId"].ToString();
					}
					if(dt.Rows[n]["date"]!=null && dt.Rows[n]["date"].ToString()!="")
					{
						model.date=DateTime.Parse(dt.Rows[n]["date"].ToString());
					}
					if(dt.Rows[n]["consumeType"]!=null && dt.Rows[n]["consumeType"].ToString()!="")
					{
						model.consumeType=int.Parse(dt.Rows[n]["consumeType"].ToString());
					}
					if(dt.Rows[n]["consumeTimes"]!=null && dt.Rows[n]["consumeTimes"].ToString()!="")
					{
						model.consumeTimes=dt.Rows[n]["consumeTimes"].ToString();
					}
					if(dt.Rows[n]["consumeMoney"]!=null && dt.Rows[n]["consumeMoney"].ToString()!="")
					{
						model.consumeMoney=decimal.Parse(dt.Rows[n]["consumeMoney"].ToString());
					}
					if(dt.Rows[n]["cardPayMoney"]!=null && dt.Rows[n]["cardPayMoney"].ToString()!="")
					{
						model.cardPayMoney=decimal.Parse(dt.Rows[n]["cardPayMoney"].ToString());
					}
					if(dt.Rows[n]["cashPayMoney"]!=null && dt.Rows[n]["cashPayMoney"].ToString()!="")
					{
						model.cashPayMoney=decimal.Parse(dt.Rows[n]["cashPayMoney"].ToString());
					}
					if(dt.Rows[n]["cardBalance"]!=null && dt.Rows[n]["cardBalance"].ToString()!="")
					{
						model.cardBalance=decimal.Parse(dt.Rows[n]["cardBalance"].ToString());
					}
					if(dt.Rows[n]["refundmentMoney"]!=null && dt.Rows[n]["refundmentMoney"].ToString()!="")
					{
						model.refundmentMoney=decimal.Parse(dt.Rows[n]["refundmentMoney"].ToString());
					}
					if(dt.Rows[n]["refundmentIntegral"]!=null && dt.Rows[n]["refundmentIntegral"].ToString()!="")
					{
						model.refundmentIntegral=int.Parse(dt.Rows[n]["refundmentIntegral"].ToString());
					}
					if(dt.Rows[n]["exchangeIntegral"]!=null && dt.Rows[n]["exchangeIntegral"].ToString()!="")
					{
						model.exchangeIntegral=int.Parse(dt.Rows[n]["exchangeIntegral"].ToString());
					}
					if(dt.Rows[n]["consumeIntegral"]!=null && dt.Rows[n]["consumeIntegral"].ToString()!="")
					{
						model.consumeIntegral=int.Parse(dt.Rows[n]["consumeIntegral"].ToString());
					}
					if(dt.Rows[n]["totalIntegral"]!=null && dt.Rows[n]["totalIntegral"].ToString()!="")
					{
						model.totalIntegral=int.Parse(dt.Rows[n]["totalIntegral"].ToString());
					}
					if(dt.Rows[n]["savingMoney"]!=null && dt.Rows[n]["savingMoney"].ToString()!="")
					{
						model.savingMoney=decimal.Parse(dt.Rows[n]["savingMoney"].ToString());
					}
					if(dt.Rows[n]["details"]!=null && dt.Rows[n]["details"].ToString()!="")
					{
					model.details=dt.Rows[n]["details"].ToString();
					}
                    if (dt.Rows[n]["Discount"] != null && dt.Rows[n]["Discount"].ToString() != "")
                    {
                        model.Discount =Convert.ToSingle(dt.Rows[n]["Discount"]);
                    }
                    if (dt.Rows[n]["jiedairen"] != null && dt.Rows[n]["jiedairen"].ToString() != "")
                    {
                        model.Jiedairen = dt.Rows[n]["jiedairen"].ToString();
                    }
                    if (dt.Rows[n]["Checkout"] != null && dt.Rows[n]["Checkout"].ToString() != "")
                    {
                        model.Checkout = dt.Rows[n]["Discount"].ToString();
                    }
                    if (dt.Rows[n]["Voucher"] != null && dt.Rows[n]["Voucher"].ToString() != "")
                    {
                        model.Voucher = dt.Rows[n]["Voucher"].ToString();
                    }
                    if (dt.Rows[n]["VoucherMoney"] != null && dt.Rows[n]["VoucherMoney"].ToString() != "")
                    {
                        model.VoucherMoney = Convert.ToDouble(dt.Rows[n]["VoucherMoney"]);
                    }
                    if (dt.Rows[n]["ChangepricePeople"] != null && dt.Rows[n]["ChangepricePeople"].ToString() != "")
                    {
                        model.ChangepricePeople = dt.Rows[n]["ChangepricePeople"].ToString();
                    }
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

